#include "Protocol.hpp"
#include "Sock.hpp"

static void Usage(string proc)
{
    cout << "Usage:" << proc << "ServerIP port" << endl;
    exit(1);
}

//./CalClient ServerIP port
int main(int argc, char *argv[])
{
    if (argc != 3)
    {
        Usage(argv[0]);
    }

    int sock = Sock::Socket();
    Sock::Connect(sock, argv[1], atoi(argv[2]));

    //业务逻辑

    request_t req;
    memset(&req, 0, sizeof(req));
    cout << "Please Enter Data One#";
    cin >> req.x;
    cout << "Please Enter Data Two#";
    cin >> req.y;
    cout << "Please Enter Operator#";
    cin >> req.op;

    //将req的内容写到sock里面
    write(sock, &req, sizeof(req));

    response_t resp;
    //从sock里读取内容放到resp
    ssize_t s = read(sock, &resp, sizeof(resp));
    if (s == sizeof(resp))
    {
        cout << "code[0:success]:" << resp.code << endl;
        cout << "result:" << resp.result << endl;
    }
    return 0;
}